package com.example.demo.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @desc: <br/>
 * @author: Jingbo Hu<br/>
 * @time：2021年01⽉26⽇<br/>
 * @version：v1.0.0<br>
 */
public class JdkProxy implements InvocationHandler {

    private Object targetObject;

    public Object newProxy(Object targetObject) {
        this.targetObject = targetObject;
        return Proxy.newProxyInstance(targetObject.getClass().getClassLoader(), targetObject.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        checkPopedom();
        Object invoke = method.invoke(targetObject,args);
        return invoke;
    }

    private void checkPopedom() {
        System.out.println("======检查权限checkPopedom()======");
    }
}
